package com.chenxys.algorithm.common;

import java.util.logging.Logger;

/**
 * <p>
 *      一些对字符串的通用处理方法
 * </p>
 *
 * @author Chenxys
 * @version V1.0
 * @Package com.chenxys.algorithm.common
 * @date 2024/1/10 10:12
 * @Copyright ©
 */
@SuppressWarnings("all")
public class StringUtil {

    /**
     * <p>
     *     生成随机大写字符串
     * </p>
     * @param maxLen 最大长度
     * @return 随机大写字符串
     */
    public static String generateRandomUpperStr(int maxLen) {
        maxLen = (int) ((Math.random()) * (maxLen + 1));
        StringBuilder builder = new StringBuilder();
        char val ;
        for (int i = 0; i < maxLen; i++) {
            do {
                val =  (char)  ((Math.random()) * 90 + 1);
            } while (val < 'A');
            builder.append(val);
        }
        return builder.toString();
    }


    /**
     * <p>
     *     生成随机大写字符串
     * </p>
     * @param maxLen 最大长度
     * @param start 开始字符
     * @param end 结束字符
     * @return 随机小写字符串
     */
    public static String generateRandomLowerStr(int maxLen, int start, int end) {
        maxLen = (int) ((Math.random()) * (maxLen) + 1);
        StringBuilder builder = new StringBuilder();
        char val ;
        for (int i = 0; i < maxLen; i++) {
            do {
                val =  (char)  ((Math.random()) * 122 + 1);
            } while ((int) val < (int) start || (int) val > (int) end);
            builder.append(val);
        }
        return builder.toString();
    }

    public static void main(String[] args) {
        System.out.println(generateRandomLowerStr(4, 'a', 'd'));
    }
}
